package com.cjl.multi_thread.ok;

public class Blank implements Runnable{
    private Account account;
    private int needMoney;

    public Blank(Account account, int needMoney) {
        this.account = account;
        this.needMoney = needMoney;
    }

    @Override
    public void run() {
        synchronized (account){
            if (account.getMoney(1) <= 0){
                System.out.println("余额不足");
                return;
            }
            if ((account.getMoney(2) - needMoney )< 0){
                System.out.println(Thread.currentThread().getName()+"想取钱,但是余额不足");
                return;
            }
            System.out.println(Thread.currentThread().getName()+"取钱 "+needMoney);
            account.setMoney(account.getMoney(3)-needMoney);
            System.out.println(Thread.currentThread().getName()+"取钱后,账户剩余 "+account.getMoney(4));
        }
    }
}
